package com.spica.platform.user.exception;

import com.spica.platform.base.exception.errorcode.IErrorCode;
import com.spica.platform.common.utils.StringUtil;

import java.util.Arrays;

public enum SysUserRtnCodEnum implements IErrorCode {
    UN_KNOWN_SYS_ERROR("UN_KNOW_SYS_ERROR", "未知异常"),
    SYS_USER_00001("SYS_USER_00001", "修改用户状态操作失败"),
    SYS_USER_00002("SYS_USER_00002", "修改用户状态操作成功"),
    SYS_USER_00003("SYS_USER_00003", "修改用户密码重置失败"),
    SYS_USER_00004("SYS_USER_00004", "修改用户密码重置成功"),
    SYS_USER_00005("SYS_USER_00005", "修改用户密码失败"),
    SYS_USER_00006("SYS_USER_00006", "修改用户密码成功"),
    SYS_USER_00007("SYS_USER_00007", "删除用户失败"),
    SYS_USER_00008("SYS_USER_00008", "删除用户成功"),
    SYS_USER_00009("SYS_USER_00009", "新增或者更新用户失败"),
    SYS_USER_0000A("SYS_USER_0000A", "新增或者更新用户成功"),
    SYS_USER_0000B("SYS_USER_0000B", "用户已存在"),
    SYS_USER_0000C("SYS_USER_0000C", "成功"),
    ;

    String rtnCod;
    String rtnMsg;
    SysUserRtnCodEnum(String rtnCod, String rtnMsg) {
        this.rtnCod = rtnCod;
        this.rtnMsg = rtnMsg;
    }

    @Override
    public String getRtnMessage() {
        return rtnMsg;
    }

    @Override
    public String getRtnCode() {
        return rtnCod;
    }

    @Override
    public IErrorCode getInstanceByErrorCode(String rtnCod) {
        return Arrays.stream(SysUserRtnCodEnum.values())
                .filter(sysUserRtnCodEnum -> StringUtil.equals(sysUserRtnCodEnum.rtnCod, rtnCod))
                .findFirst().orElse(SysUserRtnCodEnum.UN_KNOWN_SYS_ERROR);
    }
}
